package pl.un4giv3n.mightvsmagic.admin.action;

import javax.persistence.EntityManager;

import pl.un4giv3n.mightvsmagic.action.PersistenceAction;
import pl.un4giv3n.mightvsmagic.entity.User;
import pl.un4giv3n.mightvsmagic.entity.UserType;

/**
 * @author andrzejewskia go-to-admin-main page action
 */
public class AddAdminPageAction extends PersistenceAction {

	private static final long serialVersionUID = 1L;
	/**
	 * session user
	 */
	private User user;

	@Override
	public String execute() {
		EntityManager em = getEntityManager();
		user = getSessionUser(em);
		if (user == null || user.getUserType() != UserType.ADMIN) {
			addActionError("Zaloguj się");
			em.close();
			return LOGIN;
		}
		em.close();
		return SUCCESS;
	}

}
